<template>
  <div>
    <div class="now-header">
      <div>
        <span v-if="order.bet_direction === 1" class="up">涨</span>
        <span v-else class="down">跌</span>
        <span class="period">{{order.odds.period.bet.bet_asset.symbol}} {{order.snapshot.created_at.substring(0,10)}}</span>
        <span class="symbol">{{order.odds.period.bet.pay_asset.symbol}}</span>
        <span class="periodType">{{order.odds.period.bet.period_type_display}}</span>
      </div>
      <div class="ordertime">{{order.snapshot.created_at | moment("YYYY-MM-DD hh:mm:ss")}}</div>
    </div>
    <van-row type="flex" class="orderTitle">
      <van-col span="5">开奖价格</van-col>
      <van-col span="5">开奖结果</van-col>
      <van-col span="4">数量</van-col>
      <van-col span="6">区间</van-col>
      <van-col span="4">赔率</van-col>
    </van-row>
    <van-row type="flex" justify="center" class="orderDetail">
      <van-col span="5">{{oddsStartPrice}}</van-col>
      <van-col span="5">{{oddsEndPrice}}</van-col>
      <van-col span="4">{{order.quantity.toFixed(3)}}</van-col>
      <van-col span="6">{{order.odds.period.period_code.substring(10)}}</van-col>
      <van-col span="4">
        <div v-if=" type === 'now'">
          <span  v-if="order.bet_direction === 1">{{nowOddsBull}}</span>
          <span  v-else>{{nowOddsBear}}</span>
        </div>
        <div v-if=" type === 'old'">
          <span  v-if="order.bet_direction === 1">{{oddsOddsBull}}</span>
          <span  v-else>{{oddsOddsBear}}</span>
        </div>
      </van-col>
    </van-row>
    <div class="now-footer">
      <span v-if="order.odds.result === 0">
        保证金
        <span class="promisemoney">{{order.quantity.toFixed(3)}}</span>
      </span>
      <span v-else>
        盈亏
        <span v-if="order.bet_direction === order.odds.result">
          <span v-if="order.bet_direction === 1" class="winmoney">+{{(order.quantity * order.odds.odds_bull).toFixed(3)}}</span>
          <span v-else class="winmoney">+{{(order.quantity * order.odds.odds_bear).toFixed(3)}}</span>
        </span>
        <span class="loosemoney" v-else>-{{order.quantity.toFixed(3)}}</span>
      </span>
      <span>{{order.odds.period.bet.pay_asset.symbol}}</span>
    </div>
  </div>
</template>

<script>
import { Grid, GridItem, Row, Col } from 'vant'
export default {
  name: 'card-order',
  props: ['order', 'type'],
  components: {
    [Grid.name]: Grid,
    [GridItem.name]: GridItem,
    [Row.name]: Row,
    [Col.name]: Col
  },
  data () {
    return {
      headerText: ['开始价格', '开奖结果', '数量', '区间', '赔率']
    }
  },
  computed: {
    oddsStartPrice () {
      if (this.order !== null && this.order !== '') {
        if (this.order.odds.start_price !== null) {
          return this.order.odds.start_price.toFixed(2)
        } else return ''
      } else return ''
    },
    oddsEndPrice () {
      if (this.order !== null && this.order !== '') {
        if (this.order.odds.end_price !== null) {
          return this.order.odds.end_price.toFixed(2)
        } else return ''
      } else return ''
    },
    oddsOddsBull () {
      if (this.order !== null && this.order !== '') {
        if (this.order.odds.odds_bull !== null) {
          return this.order.odds.odds_bull.toFixed(3)
        } else return ''
      } else return ''
    },
    oddsOddsBear () {
      if (this.order !== null && this.order !== '') {
        if (this.order.odds.odds_bear !== null) {
          return this.order.odds.odds_bear.toFixed(3)
        } else return ''
      } else return ''
    },
    nowOddsBull () {
      if (this.order !== null && this.order !== '') {
        if (this.order.betting_bull_bear !== null) {
          return this.order.betting_bull_bear.bullish.toFixed(3)
        } else return ''
      } else return ''
    },
    nowOddsBear () {
      if (this.order !== null && this.order !== '') {
        if (this.order.betting_bull_bear !== null) {
          return this.order.betting_bull_bear.bearish.toFixed(3)
        } else return ''
      } else return ''
    }
  }
}
</script>

<style lang="less">
  .now-header{
    font-size: 15px;
    display: flex;
    justify-content: space-between;
  .up{
    color: white;
    background-color: mediumseagreen;
    padding: 4px;
    font-size: 10px;
    margin-right: 3px;
    -webkit-border-radius: 50%;
    -moz-border-radius: 50%;
    border-radius: 50%;
  }
  .down{
    color: white;
    background-color: red;
    padding: 4px;
    font-size: 10px;
    margin-right: 3px;
    -webkit-border-radius: 50%;
    -moz-border-radius: 50%;
    border-radius: 50%;
  }
  .period{
    font-size: 12px;
  }
  .symbol{
    font-size: 12px;
    color: #ffa700;
    background-color: #80808014;
    padding: 1px 2px;
    margin: 0 2px 0 2px;
  }
  .periodType{
    font-size: 12px;
    color: white;
    background-color: #05a2b2;
    padding: 1px 2px;
    margin: 0 3px;
  }
  .ordertime{
    font-size: 12px;
    margin-top: 3px;
    color: grey;
  }
  }
  .orderTitle{
    margin-top: 10px;
    padding: 10px 0px;
    /*padding-left: 10px;*/
    border-top: solid 1px #E1E4EB;;
    border-bottom: solid 1px #E1E4EB;
    .van-col{ text-align: center; }
  }
  .orderDetail{
    padding: 10px 0px;
    margin-bottom: 10px;
    text-overflow:ellipsis;
    border-bottom: solid 1px #E1E4EB;
    .van-col{
      text-align: center;
      text-overflow:ellipsis;
    }
  }
  .now-footer{
    padding-bottom: 5px;
    color: darkgrey;
    text-align: right;
  .promisemoney{
    padding: 0 5px;
    color: green;
  }
  .loosemoney{
    padding: 0 5px;
    color: red;
  }
  .winmoney{
    padding: 0 5px;
    color: green;
  }
  }
</style>
